﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLTV_V2.BussinessObject;
using QLTV_V2.BussinessLogic;
using QLTV_V2.DataAccess;

namespace QLTV_V2
{
    public partial class FrmLogin : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public FrmLogin()
        {
            InitializeComponent();
        }
        ConnectData conn = new ConnectData();
        LoginBUS loginBUS = new LoginBUS();
        private void FrmLogin_Load(object sender, EventArgs e)
        {

        }
        //Khai báo 1 hàm delegate
        public delegate void GetString(string Mystring1, string Mystring2, string Mystring3, string Mystring4);
        //khai báo 1 kiểm hàm dalegate
        public GetString MyGetData;
        bool checkLogin()
        {
            if (txt_MaNV.Text == "")
            {
                lbl_ThongBao.Text = "Chưa nhập Username";
                return false;
            }
            if (txt_MatKhau.Text == "")
            {
                lbl_ThongBao.Text = "Chua nhập Pass";
                return false;
            }
            return true;
        }

        private void btn_DangNhap_Click_1(object sender, EventArgs e)
        {
            if (checkLogin() == true)
            {
                if (loginBUS.ChekcUser(txt_MaNV.Text, txt_MatKhau.Text) == true)
                {
                    if (MyGetData != null)
                    {
                        string sql = "select * from NhanVien where MaNV='" + txt_MaNV.Text + "'";
                        DataRow dr = conn.GetDataTable(sql).Rows[0];
                        string status, manv, tenNV, timeStart;
                        status = "Xin chào : ";
                        manv = dr["MaNV"].ToString();
                        tenNV = dr["TenNV"].ToString();
                        timeStart = "Bắt đầu :" + System.DateTime.Now.ToLongTimeString();
                        MyGetData(status, manv, tenNV, timeStart);
                    }
                    this.Dispose();
                    this.Close();

                }
                else
                    lbl_ThongBao.Text = "Sai thông tin đăng nhập...";
            }
        }

        private void btn_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
